﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace WindowsGame4
{
    class Sprite
    {
        public Vector2 Position = new Vector2(0, 0);    //The current position of the Sprite
        private Texture2D mSpriteTexture;               //The texture object used when drawing the sprite
        public Rectangle Size;                          //The size of the Sprite
        public float Scale = 1.0f;                      //Used to size the Sprite up or down from the original image
        public string AssetName;                        //The asset name for the Sprite's Texture
        
        /*
         * Load the texture for the sprite using the Content Pipeline
         */
        public void LoadContent(ContentManager theContentManager, string theAssetName)
        {
            mSpriteTexture = theContentManager.Load<Texture2D>(theAssetName);
            AssetName = theAssetName;
            Size = new Rectangle(0, 0, (int)(mSpriteTexture.Width * Scale), (int)(mSpriteTexture.Height * Scale)); //to calculate and initialize the size of our Sprite
        }

        /*
         * Draw the sprite to the screen
         */
        public void Draw(SpriteBatch theSpriteBatch)
        {
            //previous: theSpriteBatch.Draw(mSpriteTexture, Position, Color.White);
            theSpriteBatch.Draw(mSpriteTexture, Position,
                new Rectangle(0, 0, mSpriteTexture.Width, mSpriteTexture.Height), Color.White,
                0.0f, Vector2.Zero, Scale, SpriteEffects.None, 0);
        }

        /*
         * Update the Sprite and change it's position based on the passed in speed, direction and elapsed time.
         */
        public void Update(GameTime theGameTime, Vector2 theSpeed, Vector2 theDirection)
        {
            Position += theDirection * theSpeed * (float)theGameTime.ElapsedGameTime.TotalSeconds;
        }
    }
}
